# Maintainer: Andrea Zagli <andrea.zagli.free@gmail.com>

_realname=meson
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.33.0
pkgrel=2
pkgdesc="High-productivity build system (mingw-w64)"
arch=('any')
url="http://mesonbuild.com/"
license=("Apache 2")
options=('strip' 'staticlibs')
depends=("${MINGW_PACKAGE_PREFIX}-python3"
         "${MINGW_PACKAGE_PREFIX}-ninja")
source=(https://github.com/mesonbuild/${_realname}/releases/download/${pkgver}/${_realname}-${pkgver}.tar.gz)
sha256sums=('c3a5bfe863b3a041469bccee9ad5b4fd7c8d451d633381fe40102731cec5b294')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  PYTHON=${MINGW_PREFIX}/bin/python3 ${MINGW_PREFIX}/bin/python3 setup.py build
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py \
    install --prefix=${MINGW_PREFIX} --root="${pkgdir}"

  PREFIX_WIN=$(cygpath -m ${MINGW_PREFIX})
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" \
    -i "${pkgdir}${MINGW_PREFIX}/bin/meson.py"
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" \
    -i "${pkgdir}${MINGW_PREFIX}/bin/mesonconf.py"
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" \
    -i "${pkgdir}${MINGW_PREFIX}/bin/mesonintrospect.py"
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" \
    -i "${pkgdir}${MINGW_PREFIX}/bin/wraptool.py"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
